<?php
include          './common/smarty.php';
include_once     '../business/market_manager.php';

//action = 1:edit; action = 2:delete; action = 3:add
$action         = $_GET["action"];
$marketID       = $_GET['id'];
$page           = $_GET['page'];
$marketMng      = new marketMng();

//SET PAGESIZE =-2;TO get the parent array with id and name;
$parents        = $marketMng->getAll($start,  -2, $sortField, $sortDirection);

//TO get one catebogy by id;
$market         = $marketMng->get($marketID);

if($action == 1){
    //TODO edit the categroy
    $tpl->assign("market",          $market);
    $tpl->assign("parents",         $parents);
    $tpl->assign("page",            $page);
    $tpl->display("../templates/marketUpdate.html");
}elseif($action == 2){
    //TODO delete one categroy
    if($marketMng->delete($marketID)){
        echo "<script>alert('delete successful!')</script>";
        echo "<script>window.location='marketList.php?page=$page'</script>";
    }else{
        echo "Delete Fails";
    }
}elseif($action == 3){
    //TODO add a new market
    $tpl->assign("id",              -1);
    $tpl->assign("page",            $page);
    $tpl->assign("parents",         $parents);

    $tpl->display("../templates/marketAdd.html");
}
?>
